home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / GDIDIB.PAK / INIT.C < prev    next >
C/C++ Source or Header  |  1997-05-06  |  6KB  |  161 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993 - 1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:   init.c
  9. //
  10. //  PURPOSE:   Performs application and instance specific initialization.
  11. //
  12. //  FUNCTIONS:
  13. //    InitApplication() - Initializes window data and registers window.
  14. //
  15. //  COMMENTS:
  16. //
  17.  
  18. #include <windows.h>            // required for all Windows applications
  19. #include "globals.h"            // prototypes specific to this application
  20. #include "resource.h"
  21. #include "palctrl.h"            // prototype for RegisterPalCtrlClass
  22.  
  23. // Global variables for application info
  24. HINSTANCE hInst;                // current instance
  25. char      szAppName[9];         // the name of this application
  26. HMENU     hMenu;                // handle of application menu
  27. HICON     hIcon;                // handle of application icon
  28. HWND      hWndClient;           // handle of client window
  29.  
  30. // palette-related global variables
  31. BOOL      bPalDevice = FALSE;   // indicates palette support of display device
  32. HPALETTE  hPalette = NULL;      // handle of current palette
  33.                                   
  34. // drawing-related global variables                                  
  35. LOGPEN   logPen;                // structure for pen attributes
  36. LOGBRUSH logBrush;              // structure for brush attributes
  37.                                   
  38. // Global variables for current DIB section
  39. char     szCurrentFile[255]; 
  40. HBITMAP  hBitmap  = NULL;
  41. HANDLE   hDIBInfo = NULL;
  42. LPVOID   lpvBits  = NULL;
  43. BOOL     fChanges = FALSE;
  44.  
  45. //
  46. //  FUNCTION: InitApplication(HINSTANCE, int)
  47. //
  48. //  PURPOSE: Initializes window data and registers window class.
  49. //
  50. //  PARAMETERS:
  51. //    hInstance - The handle to the instance of this application that
  52. //                is currently being executed.
  53. //    nCmdShow  - Specifies how the main window is to be displayed.
  54. //
  55. //  RETURN VALUE:
  56. //    TRUE  - Success
  57. //    FALSE - Initialization failed
  58. //
  59. //  COMMENTS:
  60. //
  61. //    This function is called at application initialization time.  It
  62. //    performs initialization tasks for the current application instance.
  63. //    Unlike Win16, in Win32, each instance of an application must register
  64. //    window classes.
  65. //
  66. //    In this function, we initialize a window class by filling out a data
  67. //    structure of type WNDCLASS and calling the Windows RegisterClass()
  68. //    function.  Then we create the main window and show it.
  69. //
  70. //
  71.  
  72. BOOL InitApplication(HINSTANCE hInstance, int nCmdShow)
  73. {
  74.     WNDCLASSEX  wc;
  75.     HWND        hwnd;        // Main window handle.
  76.     char        szTitle[40]; // The title bar text
  77.     
  78.     // Load the application name and description strings.
  79.  
  80.     LoadString(hInstance, IDS_APPNAME, szAppName, sizeof(szAppName));
  81.     LoadString(hInstance, IDS_DESCRIPTION, szTitle, sizeof(szTitle));
  82.  
  83.     // Save the instance handle in static variable, which will be used in
  84.     // many subsequence calls from this application to Windows.
  85.  
  86.     hInst = hInstance; // Store instance handle in our global variable 
  87.     
  88.     // Store application icon handle
  89.     hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPICON));
  90.  
  91.     // Fill in window class structure with parameters that describe the
  92.     // main window.
  93.  
  94.     wc.cbSize        = sizeof(WNDCLASSEX);
  95.     wc.style         = CS_HREDRAW | CS_VREDRAW; // Class style(s).
  96.     wc.lpfnWndProc   = (WNDPROC)WndProc;        // Window Procedure
  97.     wc.cbClsExtra    = 0;                       // No per-class extra data.
  98.     wc.cbWndExtra    = 0;                       // No per-window extra data.
  99.     wc.hInstance     = hInstance;               // Owner of this class
  100.     wc.hIcon         = hIcon;
  101.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW); // Cursor
  102.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); // Default color
  103.     wc.lpszMenuName  = szAppName;               // Menu name from .RC
  104.     wc.lpszClassName = szAppName;               // Name to register as
  105.     wc.hIconSm       = LoadImage(hInstance,        // Load small icon image
  106.                                  MAKEINTRESOURCE(IDI_APPICON),
  107.                                  IMAGE_ICON,
  108.                                  16, 16,
  109.                                  0);
  110.  
  111.     // Register the window class and return FALSE if unsuccesful.
  112.  
  113.     if (!RegisterClassEx(&wc))
  114.     {
  115.         //Assume we are running on NT where RegisterClassEx() is
  116.         //not implemented, so let's try calling RegisterClass().
  117.  
  118.         if (!RegisterClass((LPWNDCLASS)&wc.style))
  119.             return FALSE;
  120.     }
  121.  
  122.     // Register window class for the client window.
  123.     
  124.     wc.lpfnWndProc   = ClientWndProc;
  125.     wc.hIcon         = NULL;
  126.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); // Default color
  127.     wc.lpszMenuName  = NULL;
  128.     wc.lpszClassName = "ClientWndClass";
  129.  
  130.     if (!RegisterClass((LPWNDCLASS)&wc.style))
  131.         return FALSE;
  132.       
  133.     // Register palette control class
  134.     if (!RegisterPalCtrlClass(hInstance))
  135.     {
  136.         return FALSE;
  137.     }
  138.               
  139.     // Create a main window for this application instance.
  140.     hwnd = CreateWindow(szAppName,           // See RegisterClass() call
  141.                         szTitle,             // Text for window title bar
  142.                         WS_OVERLAPPEDWINDOW, // Window style
  143.                         CW_USEDEFAULT, 0,    // Use default positioning
  144.                         CW_USEDEFAULT, 0,    // Use default size
  145.                         NULL,                // Overlapped has no parent
  146.                         NULL,                // Use the window class menu
  147.                         hInstance,           // This instance owns this window
  148.                         NULL                 // Don't need data in WM_CREATE
  149.     );
  150.     
  151.     if (!hwnd)
  152.         // window could not be created, return "failure"
  153.         return FALSE;
  154.         
  155.     // Make the window visible; update its client area; and return "success"
  156.     ShowWindow(hwnd, nCmdShow);  // Show the window
  157.     UpdateWindow(hwnd);          // Sends WM_PAINT message
  158.     
  159.     return TRUE;           
  160. }
  161.